var __extends =
    (this && this.__extends) ||
    (function () {
      var e = function (t, i) {
        return (e =
          Object.setPrototypeOf ||
          ({ __proto__: [] } instanceof Array &&
            function (e, t) {
              e.__proto__ = t;
            }) ||
          function (e, t) {
            for (var i in t)
              Object.prototype.hasOwnProperty.call(t, i) && (e[i] = t[i]);
          })(t, i);
      };
      return function (t, i) {
        function n() {
          this.constructor = t;
        }
        if ("function" != typeof i && null !== i)
          throw new TypeError(
            "Class extends value " + String(i) + " is not a constructor or null"
          );
        e(t, i),
          (t.prototype =
            null === i
              ? Object.create(i)
              : ((n.prototype = i.prototype), new n()));
      };
    })(),
  MineralStoneMainView = (function (e) {
    function t() {
      var t = e.call(this) || this;
      return (
        t.tab_mineral_stone.on(
          Laya.Event.CLICK,
          t,
          t.onTabMineralStoneDidClickFn
        ),
        t.btn_mineral_close.on(Laya.Event.CLICK, t, t.onMineralCancle),
        WebSocketService.addListener({
          caller: t,
          code: 12751,
          method: t.onLoadMineralStoneData,
        }),
        WebSocketService.addListener({
          caller: t,
          code: 12961,
          method: t.onLoadMineralStoneData,
        }),
        WebSocketService.addListener({
          caller: t,
          code: 12911,
          method: t.onLoadStoneHeChengData,
        }),
        WebSocketService.addListener({
          caller: t,
          code: 1296,
          method: t.onLoadStoneHuiShouData,
        }),
        (t.list_mineral_tableView.vScrollBarSkin = ""),
        (t.list_mineral_tableView.selectEnable = !0),
        t.list_mineral_tableView.on(
          Laya.Event.CLICK,
          t,
          t.onMineralListDidClickAction
        ),
        (t.list_mineral_tableView.renderHandler = new Laya.Handler(
          t,
          t.updateMineralItem
        )),
        (t.list_stone_huishou.vScrollBarSkin = ""),
        (t.list_stone_huishou.selectEnable = !0),
        t.list_stone_huishou.on(
          Laya.Event.CLICK,
          t,
          t.onHuiShouListDidClickAction
        ),
        t
      );
    }
    return (
      __extends(t, e),
      (t.openMineralStoneView = function (e) {
        return (
          null == this.mineralStoneVC && (this.mineralStoneVC = new t()),
          (this.mineralStoneVC.tab_mineral_stone.selectedIndex = 0),
          (this.mineralStoneVC.list_mineral_tableView.visible = !1),
          (this.mineralStoneVC.list_stone_huishou.visible = !1),
          (this.mineralStoneVC.type = e),
          "矿石合成" == e
            ? (WebSocketService.send({ c: 12751, d: { type: 1 } }),
              (this.mineralStoneVC.label_stone_main_title.text = "矿石合成"))
            : "矿石回收" == e &&
              (WebSocketService.send({ c: 12961, d: { type: 1 } }),
              (this.mineralStoneVC.label_stone_main_title.text = "矿石回收")),
          this.mineralStoneVC
        );
      }),
      (t.prototype.onTabMineralStoneDidClickFn = function () {
        var e = this.tab_mineral_stone.selectedIndex;
        "矿石合成" == this.type
          ? 0 == e
            ? WebSocketService.send({ c: 12751, d: { type: 1 } })
            : 1 == e
            ? WebSocketService.send({ c: 12751, d: { type: 2 } })
            : 2 == e && WebSocketService.send({ c: 12751, d: { type: 3 } })
          : "矿石回收" == this.type &&
            (0 == e
              ? WebSocketService.send({ c: 12961, d: { type: 1 } })
              : 1 == e
              ? WebSocketService.send({ c: 12961, d: { type: 2 } })
              : 2 == e && WebSocketService.send({ c: 12961, d: { type: 3 } }));
      }),
      (t.prototype.onLoadMineralStoneData = function (e) {
        if ("12751" == e.act_id || "12961" == e.act_id) {
          this.listArr = e.data;
          var t = void 0;
          if (((this.dataSource = []), "矿石合成" == this.type))
            for (i = 0; i < this.listArr.length; i++) {
              (t = {
                item1: {
                  text: (n = this.listArr[i]).oreName + "(" + n.num + ")",
                },
                item4: { text: "(" + n.priceOne + "银)" },
                item5: { text: "(" + n.priceAll + "银)" },
                goodsId: n.goodsId,
                num: n.num,
                oreName: n.oreName,
                priceAll: n.priceAll,
                priceOne: n.priceOne,
              }),
                this.dataSource.push(t);
            }
          else if ("矿石回收" == this.type)
            for (var i = 0; i < this.listArr.length; i++) {
              var n = this.listArr[i];
              (t = {
                item_huishou_name: { text: n.name + "(" + n.num + ")" },
                item_huishou_cost: { text: "(" + n.price + "银/个)" },
                goodsId: n.goodsId,
                num: n.num,
                oreName: n.name,
                price: n.price,
              }),
                this.dataSource.push(t);
            }
        }
        this.listArr.length > 0 &&
          ("矿石合成" == this.type
            ? ((this.list_mineral_tableView.visible = !0),
              (this.list_mineral_tableView.dataSource = this.dataSource))
            : "矿石回收" == this.type &&
              ((this.list_stone_huishou.visible = !0),
              (this.list_stone_huishou.dataSource = this.dataSource)));
      }),
      (t.prototype.updateMineralItem = function (e, t) {
        if ("矿石合成" == this.type) {
          if (t > this.dataSource.length) return;
          var i = e.getChildByName("item2"),
            n = e.getChildByName("item3"),
            o = e.dataSource;
          if (o.num < 2)
            return (
              (i.skin = "comp/commonpic/btn_dialog_silver.png"),
              void (n.skin = "comp/commonpic/btn_dialog_silver.png")
            );
          new Array();
          if (o.oreName.split("级")[0] >= 10)
            return (
              (i.skin = "comp/commonpic/btn_dialog_silver.png"),
              void (n.skin = "comp/commonpic/btn_dialog_silver.png")
            );
          (i.skin = "comp/commonpic/btn_dialog_sure.png"),
            (n.skin = "comp/commonpic/btn_dialog_sure.png");
        }
      }),
      (t.prototype.onMineralListDidClickAction = function (e) {
        if ("" != e.target.name) {
          var t = this.list_mineral_tableView.selectedItem;
          if (!(t.num < 2)) {
            new Array();
            if (!(t.oreName.split("级")[0] >= 10))
              if ("item2" == e.target.name) {
                var i = "确定花费" + t.priceOne + "银，合成一次？";
                NormalDialog.showNormalDialog(i, this, this.onDidClickSure);
              } else
                "item3" == e.target.name &&
                  CommonInputSelectDialog.showCommonInputDialog("矿石合成", t);
          }
        }
      }),
      (t.prototype.onDidClickSure = function () {
        var e = this.list_mineral_tableView.selectedItem;
        WebSocketService.send({
          c: 12911,
          d: { type: 1, goodsId: e.goodsId, num: 2 },
        });
      }),
      (t.prototype.onLoadStoneHeChengData = function (e) {
        ToastView.toastView(e.msg), this.onTabMineralStoneDidClickFn();
      }),
      (t.prototype.onLoadStoneHuiShouData = function (e) {
        ToastView.toastView(e.msg), this.onTabMineralStoneDidClickFn();
      }),
      (t.prototype.onHuiShouListDidClickAction = function (e) {
        if ("" != e.target.name && "item_huishou" == e.target.name) {
          var t = this.list_stone_huishou.selectedItem;
          CommonInputSelectDialog.showCommonInputDialog("矿石回收", t);
        }
      }),
      (t.prototype.onMineralCancle = function () {
        this.removeSelf();
      }),
      t
    );
  })(ui.CompoundController.MineralStoneMainViewUI);
